package org.example.fanruan;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Yyming
 * @version 10.0
 * Created by Yyming on 2020/7/8
 */
public class CommonArray {

    public static void main(String[] args) throws IOException, NoSuchAlgorithmException {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(new FileInputStream("4.in"))));
        in.nextToken();
        int m = (int) in.nval;
        int[] num1 = new int[m];
        for (int i = 0; i < m; i++) {
            in.nextToken();
            num1[i] = (int) in.nval;
        }
        in.nextToken();
        int n = (int) in.nval;
        List<Integer> common = new ArrayList<>();
        int index = 0;
        int last = 0;
        outer:
        for (int i = 0; i < n; i++) {
            in.nextToken();
            int temp = (int) in.nval;
            if (temp == last) {
                continue;
            } else {
                last = temp;
            }
            while (index < m && num1[index] != temp){
                if (num1[index] > temp) {
                    continue outer;
                }
                index++;
            }
            if (index == m){
                break;
            }
            common.add(temp);
            index++;
        }
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(common.toString().getBytes());
        byte[] md5s = md5.digest();
        System.out.println(common.toString());
        System.out.println(new BigInteger(1,md5s).toString(16));
    }
}
